import java.util.*;
import java.io.*;


public class StopWordRemover {
	
	/**
	 * This static method removes stopwords from the input Vector.
	 * 
	 * The file stopwords.txt contains all the stopwords to be considered.
	 * Stopwords from the file may be ignored by adding // before the word
	 * 
	 * @param words	Vector of words to be processed
	 * @return		The input Vector with the stopwords removed 
	 */
	public static Vector<String> removeStopWords(Vector<String> words)
	{
		List<String> stopwords = new ArrayList<String>();
		try {
			FileInputStream fstream = new FileInputStream("stopwords.txt");
			
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;
			
			while ((strLine = br.readLine()) != null) {
				String word = strLine.split(" ")[0];
				if (!word.startsWith("//")) // Stop words may be commented out in stopwords.txt
					stopwords.add(word);
			}
			in.close();
		} catch (Exception e) {
			System.err.println("Error reading file stopwords.txt");
			System.exit(1);
		}
		
		Vector<String> newVect = new Vector<String>();
		
		//For each word of the processed text
		for(String word : words)
		{
			
			boolean isStopWord = false;
			
			//For each word in the stopword list
			for(String stopword : stopwords)
			{
				if(word.equals(stopword))
					{
						isStopWord = true;
						break;
					}
			}
			
			//If the word isn't a stopword, put it in the list
			if(!isStopWord)
				newVect.add(word);
		}
		
		return newVect;
	}

}
